package com.iespring.controller.admin.brand;

import com.iespring.bean.admin.brand.bo.BrandBo;
import com.iespring.bean.admin.brand.po.BrandPo;
import com.iespring.bean.common.BasePageInfo;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.bean.common.CommonData;
import com.iespring.service.admin.brand.BrandService;
import com.iespring.util.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author weigwen
 * @Description:
 * @Date 2022/12/29 17:03
 */

@RestController
@RequestMapping("admin")
public class BrandController {

    @Autowired
    BrandService brandService;

    @RequestMapping("brand/list")
    public BaseRespVo brandList(BasePageInfo basePageInfo){//BasePageInfo获取入参
        //返回数据逐层封装，先到BrandPo，再到CommonData，最后到BaseRespVo
        CommonData commonData = brandService.brandList(basePageInfo);
        return BaseRespVo.ok(commonData);
    }

    @PostMapping("brand/create")
    public BaseRespVo brandCreate(@RequestBody BrandBo brandBo){//BrandBo获取入参
        //返回数据逐层封装，先到BrandBo，再到BaseRespVo
        BaseRespVo baseRespVo = brandService.brandCreate(brandBo);
        return baseRespVo;
    }

    @PostMapping("brand/update")
    public BaseRespVo brandUpdate(@RequestBody @Valid BrandPo brandPo, BindingResult bindingResult){
        ValidationUtils.validParam(bindingResult);
        BaseRespVo baseRespVo = brandService.brandUpdate(brandPo);
        return baseRespVo;
    }

    @PostMapping("brand/delete")
    public BaseRespVo brandDelete(@RequestBody BrandPo brandPo){
        BaseRespVo baseRespVo = brandService.brandDelete(brandPo);
        return baseRespVo;
    }

}
